﻿<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:WinnerSV="clr-namespace:WinnerSV.Views"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    x:Class="WinnerSV.Views.HomeView"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False" 
    DataContext="{Binding Home, Source={StaticResource Locator}}">

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded" >
            <Command:EventToCommand Command="{Binding RefreshBindingData, Mode=OneWay}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <!--LayoutRoot contains the root grid where all other page content is placed-->
    <Grid x:Name="LayoutRoot">
        <phone:Panorama Template="{StaticResource PanoramaControlTemplateWinner}" 
                        ItemContainerStyle="{StaticResource PanoramaItemStyleWinner}">

            <phone:Panorama.Background>
                <ImageBrush ImageSource="/Assets/PanoramaBackground.png" Stretch="Fill"/>
            </phone:Panorama.Background>

            <phone:Panorama.Title>
                <Border Background="Transparent">
                    <TextBlock Text="{Binding LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}" 
                               Foreground="{StaticResource paletteWinnerYellowDark}" 
                               FontFamily="Segoe WP Black" 
                               FontSize="130" 
                               Margin="0,20" />
                </Border>
            </phone:Panorama.Title>


            <!-- Pivot 1 -->
            <phone:PanoramaItem x:Name="panoramaItem" Header=" ">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <Grid Grid.Row="0" Margin="40">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        
                        <Image Source="/Assets/Add.png" 
                               Stretch="None" 
                               Grid.Column="0" />
                        <TextBlock x:Name="textBlock"
                                   Grid.Column="1"
                                   DataContext="{Binding NuovaSchedina}"
                                   FontSize="{StaticResource PhoneFontSizeLarge}" 
                                   Text="{Binding Title}" 
                                   VerticalAlignment="Center">
                        </TextBlock>
                        
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Tap">
                                <Command:EventToCommand Command="{Binding Home.NavToPageCommand, Mode=OneWay, Source={StaticResource Locator}}" 
                                                        CommandParameter="{Binding DataContext, ElementName=textBlock}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </Grid>
                    
                    <WinnerSV:AdsControl VerticalAlignment="Bottom"
                                         Grid.Row="1"/>
                </Grid>
            </phone:PanoramaItem>

            <!-- Pivot 2 -->
            <phone:PanoramaItem Header="{Binding LocalizedResources.PanoramaPivot2Header, Source={StaticResource LocalizedStrings}}" >
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <ListBox x:Name="listBox" 
                             Grid.Row="0"
                             ItemsSource="{Binding Schedine}" >
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        
                                        <Image Grid.Column="0" Source="/Assets/Pin.png" />
                                        <TextBlock Grid.Column="1" Text="{Binding Path=Title}" VerticalAlignment="Center" />
                                        
                                        <toolkit:ContextMenuService.ContextMenu>
                                            <toolkit:ContextMenu>
                                                <toolkit:MenuItem Header="{Binding LocalizedResources.ContextMenuItemDelete, Mode=OneWay, Source={StaticResource LocalizedStrings}}" 
                                                                  Command="{Binding Home.DeleteSchedinaCommand, Mode=OneWay, Source={StaticResource Locator}}" 
                                                                  CommandParameter="{Binding}" />
                                            </toolkit:ContextMenu>
                                        </toolkit:ContextMenuService.ContextMenu>
                                    </Grid>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>

                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Tap">
                                <Command:EventToCommand Command="{Binding Home.NavToPageCommand, Mode=OneWay, Source={StaticResource Locator}}" 
                                                        CommandParameter="{Binding SelectedItem, ElementName=listBox}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </ListBox>
                </Grid>
            </phone:PanoramaItem>

            <!-- Pivot 3 -->
            <phone:PanoramaItem Header="{Binding LocalizedResources.PanoramaPivot3Header, Source={StaticResource LocalizedStrings}}" >
                <WinnerSV:PivotAbout/>
            </phone:PanoramaItem>
        </phone:Panorama>
    </Grid>

</phone:PhoneApplicationPage>